package com.henu.adapter;

import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;

import java.util.ArrayList;

/**
 * Created by xing on 2017/5/16.
 */

public class ViewpageAdapter extends PagerAdapter {
    private ArrayList<View> viewlist=new ArrayList<>();
    public void addData(ArrayList<View> templist){
        viewlist.addAll(templist);
    }
    @Override
    public int getCount() {
        return viewlist.size();
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view =viewlist.get(position);
        ViewGroup parent= (ViewGroup) view.getParent();
        if(parent!=null){
            parent.removeView(view);
        }
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        View view=viewlist.get(position);
        container.removeView(view);

    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }
}
